#!/usr/bin/python
# Filename: 15.py
import StringIO
import urllib
import Image
import sys
from os import sep as PSEP
#print PSEP
out_dir = sys.path[0]+PSEP+"resources"+PSEP
data = urllib.urlopen('http://huge:file@www.pythonchallenge.com/pc/return/wire.png').read()
im = Image.open(StringIO.StringIO(data))
new_im = Image.new(im.mode, (100, 100))
# im.save('D:\\wire.png')
# im.show()
k = 9999
for i in range(50):
	sx, sy = 50+i, 50+i
	for j in range(sx, sx-(i+1)*2, -1):
		p = im.getpixel((k, 0))
		k -= 1
		new_im.putpixel((j, sy), p)
	sx = sx-i*2-1
	for j in range(sy-1, sy-(i+1)*2, -1):
		p = im.getpixel((k, 0))
		k -= 1
		new_im.putpixel((sx, j), p)
	sy = sy-i*2-1
	for j in range(sx+1, sx+(i+1)*2):
		p = im.getpixel((k, 0))
		k -= 1
		new_im.putpixel((j, sy), p)
	sx = sx+2*i+1
	for j in range(sy+1, sy+i*2+1):
		p = im.getpixel((k, 0))
		k -= 1
		new_im.putpixel((sx, j), p)
new_im.save(out_dir+"15.png")

#cat==>cat.html==>uzi.html